package com.hbut.friend.controller.user;

import com.hbut.common.core.Controller.BaseController;
import com.hbut.common.core.constants.HttpConstants;
import com.hbut.common.core.domain.R;
import com.hbut.common.core.domain.vo.LoginUserVO;
import com.hbut.friend.domain.user.dto.LoginDTO;
import com.hbut.friend.domain.user.dto.UserDTO;
import com.hbut.friend.domain.user.vo.UserVO;
import com.hbut.friend.service.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    @Autowired
    private IUserService IUserService;

    @PostMapping("/sendCode" )
    public R<Void> sendCode(@RequestBody UserDTO userDTO) {
        return toR(IUserService.sendCode(userDTO));
    }

    @PostMapping("/code/login")
    public R<String> codeLogin(@RequestBody LoginDTO loginDTO){
        return R.ok(IUserService.codeLogin(loginDTO.getPhone(), loginDTO.getCode()));
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toR(IUserService.logout(token));
    }

    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return IUserService.info(token);
    }

    @GetMapping("/detail")
    public R<UserVO> detail(){
        return R.ok(IUserService.detail());
    }
}
